package com.awspaas.user.apps.processforsap.event;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.bpmn.engine.listener.ListenerConst;
import com.actionsoft.sdk.local.SDK;

import java.util.List;

public class MMFormAfterSave extends ExecuteListener {
    @Override
    public void execute(ProcessExecutionContext param) throws Exception {//BO表名
        String boName = param.getParameterOfString(ListenerConst.FORM_EVENT_PARAM_BONAME);
        BO formData = (BO) param.getParameter(ListenerConst.FORM_EVENT_PARAM_FORMDATA);
        if (boName.equals("BO_EU_SAP_CCST")){
            String shelfLife= formData.getString("SHELF_LIFE");
            List<BO> list = SDK.getBOAPI().query(boName).bindId(formData.getBindId()).list();
            for (BO bo:list){
                bo.set("SHELF_LIFE",shelfLife);
                SDK.getBOAPI().update(boName,bo);
            }
        }
        if (boName.equals("BO_EU_SAP_JBST")){
            formData.set("STATUS","update");
            SDK.getBOAPI().update(boName,formData);
        }

        //处理物料特性
        if ("BO_EU_SAP_WAFER".equals(boName)){
            //如果填了型号，对型号的特殊值进行处理
            String ztype= formData.getString("ZTYPE");
            String newValue = ztype.replace("\\","-")
                    .replace("/","-")
                    .replace(":","-")
                    .replace("*","-")
                    .replace("?","-")
                    .replace("\"","-")
                    .replace("<","-")
                    .replace(">","-")
                    .replace("|","-");
            if (!ztype.equals(newValue)){
                formData.set("ZIMPTYPE",ztype);
                formData.set("ZTYPE",newValue);
                SDK.getBOAPI().update(boName,formData);
            }

        }

    }
}
